<template>
  <div class="search-header">
    <el-card>
      <el-form :model="searchform" label-width="auto">
        <el-form-item
          v-for="item in inputArray"
          :key="item.key"
          :label="item.label"
        >
          <el-input
            v-model="searchform[item.key]"
            :placeholder="item.placeholder"
          />
        </el-form-item>
        <el-form-item
          v-for="item in selectArray"
          :key="item.key"
          :label="item.label"
        >
          <el-select v-model="searchform[item.key]" :placeholder="item.placeholder">
            <el-option
              v-for="it in item.data"
              :key="it.value"
              :label="it.label"
              :value="it.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="el-base-button" style="margin-right: 10px" @click="search">搜索</el-button>
          <el-button class="el-base-button" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  props: {
    inputArray: {
      type: Array,
      default: () => []
    },
    selectArray: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      searchform: {}
    }
  },
  methods: {
    // 点击搜索
    search() {
      this.$emit('search', { ...this.searchform })
    },
    // 重置
    reset() {
      this.searchform = {}
      this.$emit('search', {})
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form {
  display: flex;
  flex-wrap: wrap;
}
.el-input, .el-select {
  width: 260px;
  margin-right: 16px;
}
::v-deep .el-card__body {
  padding-bottom: 0;
}
::v-deep .el-form-item__label {
  font-weight: 400;
}
</style>
